package com.allwees.bs.c.module.app.controller;

import com.allwees.bs.core.modelbase.vo.R;
import com.allwees.core.common.util.http.RequestUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Daniel
 * @version 1.0.0
 * @since 2020/12/6 12:10
 */
@RestController
public class CountryChooserController {

    @Autowired
    private SiteInfoHelper helper;

    @GetMapping("/api/country/resolve")
    public R resolveCountry(HttpServletRequest request) {
        Map<String, Object> param = new HashMap<>();
        String ip = RequestUtil.getIpFromRequest(request);
        param.put("ip", ip);
        param.putAll(helper.getInfo(ip));
        return R.ok(param);
    }
}
